package org.tmad.ocms.web;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.tmad.ocms.log.LogFactory;

import java.lang.String;

/**
 * Servlet implementation class AdminidtratorServlet
 */
public class AdminidtratorServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private static Logger logger = LogFactory.getLogger();
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AdminidtratorServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		RequestDispatcher dispatcher = getServletContext()
				.getRequestDispatcher("/adminlogin.jsp");
		dispatcher.forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String email = request.getParameter("email");
		String password = request.getParameter("password");
		String mail="ocmshelp2012@gmail.com";
		String pwd="08f91a0528";
		if ((email.equals(mail))&&(password.equals(pwd))) {
			
			RequestDispatcher dispatcher = getServletContext()
					.getRequestDispatcher("/adminhome.jsp");
			dispatcher.forward(request, response);
		}
		else{
			logger.info("Login failed for user " + email);
			request.setAttribute("error", "User name or password is invalid");
			RequestDispatcher dispatcher = getServletContext()
					.getRequestDispatcher("/login.jsp");
			dispatcher.forward(request, response);

		
		}
			
	}

}
